/* GUI CONVERTED from reoptr13.p (converter v1.76) Sun Aug 25 20:59:47 2002 */
/* reoptr13.p - LABOR REWORK TRANSACTION BY PART (REPETITIVE)           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.8.3.5 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 5.0      LAST MODIFIED: 05/19/89   BY: emb      */
/* REVISION: 5.0      LAST MODIFIED: 10/17/90   BY: emb *B801*/
/* REVISION: 6.0      LAST MODIFIED: 09/25/90   BY: SMM *D072*/
/* REVISION: 6.0      LAST MODIFIED: 10/18/90   BY: SMM *D108*/
/* REVISION: 6.0      LAST MODIFIED: 11/20/90   BY: emb *D223*/
/* REVISION: 6.0      LAST MODIFIED: 03/22/91   BY: emb *D448*/
/* REVISION: 6.0      LAST MODIFIED: 04/09/91   BY: WUG *D503*/
/* REVISION: 6.0      LAST MODIFIED: 06/14/91   BY: emb *D705*/
/* REVISION: 6.0      LAST MODIFIED: 08/09/91   BY: pma *D806*/
/* REVISION: 7.0      LAST MODIFIED: 10/08/91   BY: pma *F003*             */
/* REVISION: 7.0      LAST MODIFIED: 03/09/92   BY: smm *F230*             */
/* REVISION: 7.0      LAST MODIFIED: 03/19/92   BY: RAM *F298*             */
/* REVISION: 7.0      LAST MODIFIED: 03/22/92   BY: pma *F089*             */
/* REVISION: 7.0      LAST MODIFIED: 03/30/92   BY: emb *F331*             */
/* REVISION: 7.0      LAST MODIFIED: 06/16/92   BY: emb *F620*             */
/* REVISION: 7.0      LAST MODIFIED: 06/17/92   BY: emb *F662*             */
/* REVISION: 7.0      LAST MODIFIED: 10/13/92   BY: emb *G184*             */
/* REVISION: 7.3      LAST MODIFIED: 03/01/93   BY: emb *G760*             */
/* REVISION: 7.3      LAST MODIFIED: 08/31/93   BY: emb *GE62*(rev only)   */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN76*             */
/* REVISION: 7.3      LAST MODIFIED: 12/23/94   BY: cpp *FT95*             */
/* REVISION: 7.3      LAST MODIFIED: 05/11/95   BY: ais *G0MM*             */
/* REVISION: 7.3      LAST MODIFIED: 11/28/95   BY: jym *F0WD*             */
/* REVISION: 7.3      LAST MODIFIED: 02/22/96   BY: jym *G1N7*             */
/* REVISION: 7.3      LAST MODIFIED: 03/27/96   BY: jym *G1Q9*             */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: aal *K001*             */
/* REVISION: 8.6      LAST MODIFIED: 01/15/97   BY: *G2JW* Julie Milligan  */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane       */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan      */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan      */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates      */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb             */
/* Old ECO marker removed, but no ECO header exists *F0PN*                 */
/* Revision: 1.8.3.4    BY: Rajesh Thomas   DATE: 06/19/01 ECO: *M18V*     */
/* $Revision: 1.8.3.5 $         BY: Vivek Gogte     DATE: 08/06/02 ECO: *N1QQ*     */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE          */
{mfdtitle.i "2+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reoptr13_p_1 "Start Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_2 "Status"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_3 "Reason"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_4 "Routing"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_5 "Down Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_6 "Completed"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_7 "Elapsed or Stop Time"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_8 "BOM"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_9 "Conv"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_10 "Control Total"
/* MaxLen: Comment: */

&SCOPED-DEFINE reoptr13_p_11 "Input Total"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

{gldydef.i new}
{gldynrm.i new}

define new global shared variable global_rsntyp as character.

define new shared variable gldetail like mfc_logical no-undo initial no.
define new shared variable gltrans like mfc_logical no-undo initial no.
define new shared variable wr_recno as recid.
define new shared variable wc_recno as recid.
define new shared variable op_recno as recid.
define new shared variable comp like ps_comp.
define new shared variable eff_date as date.
define new shared variable operation like ps_op.
define new shared variable wo_recid as recid.
define new shared variable wo_recno as recid.
define new shared variable ophist_recid as recid.
define new shared variable pay_rate like emp_pay_rate.
define new shared variable lotserial like sr_lotser no-undo.
define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
define new shared variable rework_to_lotser like wlt_lotser no-undo.
define new shared variable rework_to_lotser_ref like wlt_ref no-undo.
define new shared variable rework_lotser like wlt_lotser no-undo.
define new shared variable rework_lotser_ref like wlt_ref no-undo.
define new shared variable rework_prodby_op like wl_prodby_op no-undo.
define new shared variable last_date like op_date.
define new shared variable input_total as decimal format "->>9.9<<"
   label {&reoptr13_p_11}.
define new shared variable control_total like input_total
   label {&reoptr13_p_10}.
define new shared variable old_emp like op_emp.
define new shared variable shift like op_shift.
define new shared variable earn like op_earn.
define new shared variable site like rps_site no-undo.
define new shared variable continue as logical initial no.
define new shared variable emp_recno as recid.
define new shared variable part like op_part no-undo.
define new shared variable op like ps_op no-undo.
define new shared variable bom_code as character format "x(18)"
   label {&reoptr13_p_8}.
define new shared variable routing as character format "x(18)"
   label {&reoptr13_p_4}.
define new shared variable schedule_id like wo_lot.
define new shared variable prline like rps_line no-undo.
define new shared variable undo-all like mfc_logical no-undo.
define new shared variable conv like um_conv label {&reoptr13_p_9}.

define variable yn like mfc_logical.
define variable ref like glt_ref.
define variable wr_recid as recid.
define variable wocomp like mfc_logical label {&reoptr13_p_6} initial no.
define variable wrstatus as character format "X(8)" label {&reoptr13_p_2}.
define variable start_setup as character format "99:99:XX"
   label {&reoptr13_p_1}.
define variable start_run like start_setup.
define variable stop_setup like start_setup
   label {&reoptr13_p_7}.
define variable stop_run like stop_setup.
define variable date_change as integer.
define variable elapse as decimal format ">>>>>>>>.999".
define variable trnbr like op_trnbr format ">>>>>>>9".
define variable wrnbr like wr_nbr.
define variable i as integer.
define variable j as integer.
define variable qty like op_qty_comp.
define variable rsn_desc1 like rsn_desc.
define variable rsn_desc2 like rsn_desc.
define variable rsn_desc3 like rsn_desc.
define variable downtime like input_total extent 5 label {&reoptr13_p_5}.
define variable down_rsn like rsn_code extent 5 label {&reoptr13_p_3}.
define variable down_desc like rsn_desc extent 5.
define variable ptstatus like pt_status.
define variable msg-type as integer.
define variable locked-file as character.
define variable msg-counter as integer no-undo.
define variable um like pt_um.
define variable tot_units like op_qty_comp.
define variable disp_units as character format "x(15)".
define variable move_to_wkctr as character no-undo.
define variable move_to_mch as character no-undo.
define variable undo_stat like mfc_logical no-undo.
define variable undo-input like mfc_logical no-undo.
define variable trans-ok like mfc_logical.

define buffer ophist for op_hist.

define new shared frame a.
define new shared frame b.


{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/
{gpatrdef.i "new shared"}

if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.

last_date = today.
site = global_site.

{reopf10a.i} /* Frame a definition */

{reopf13b.i} /* Frame b definition */

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.

if available mfc_ctrl and mfc_logical = true then do:
   {pxmsg.i &MSGNUM=5122 &ERRORLEVEL=3}
   message.
   message.
   undo, leave.
end.

/* DISPLAY */
view frame a.
view frame b.

find first ea_mstr no-lock where ea_type = "1" no-error.
if available ea_mstr then earn = ea_earn.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   continue = no.
   {gprun.i ""reoptr2a.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   if not continue then leave mainloop.
   find emp_mstr no-lock where recid(emp_mstr) = emp_recno.

   repeat with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

      prompt-for
         op_part
         op_wo_op
         prline
      with frame b
      editing:

         if frame-field = "op_part" then do:

            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp.i pt_mstr op_part pt_part op_part pt_part pt_part}

            if recno <> ? then do:
               find ptp_det no-lock where ptp_part = pt_part
                  and ptp_site = site no-error.
               display pt_part @ op_part pt_desc1.

               if available ptp_det then do:
                  if ptp_routing > "" then
                     routing = ptp_routing.
                  else routing = "".
                  if ptp_bom_code > "" then
                     bom_code = ptp_bom_code.
                  else bom_code = "".
               end.
               else do:
                  if pt_routing > "" then
                     routing = pt_routing.
                  else routing = "".
                  if pt_bom_code > "" then
                     bom_code = pt_bom_code.
                  else bom_code = "".
               end.

               display pt_part @ op_part pt_desc1.

               find first ro_det no-lock where ro_routing =
                  if routing > "" then routing else pt_part no-error.
               if available ro_det
               then display ro_op @ op_wo_op ro_desc.
               else display "" @ op_wo_op "" @ ro_desc.

               display "" @ prline "" @ ln_desc.
               for each lnd_det no-lock where
                     lnd_site = site and lnd_part = pt_part
                     and (lnd_start <= input last_date or lnd_start = ?)
                  with frame b:
                  find ln_mstr no-lock where ln_line = lnd_line
                     and ln_site = lnd_site no-error.
                  if available ln_mstr
                  then display ln_line @ prline ln_desc.
                  else display "" @ prline "" @ ln_desc.
                  leave.
               end.
               display routing bom_code with frame b.
            end.
            recno = ?.
         end.
         else
         if frame-field = "op_wo_op"
            and can-find (pt_mstr where pt_part = input op_part)
         then do:

            find pt_mstr no-lock where pt_part = input op_part
               no-error.
            find ptp_det no-lock where ptp_part = pt_part
               and ptp_site = site no-error.

            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp01.i ro_det op_wo_op ro_op
               "if available ptp_det then
                   if ptp_routing > """" then ptp_routing
                   else ptp_part
                else if pt_routing > """" then pt_routing else pt_part"
               ro_routing ro_routing}

            if recno <> ? then
               display ro_op @ op_wo_op ro_desc.
         end.
         else if frame-field = "prline" then do:

            {mfnp05.i lnd_det lnd_line
               "lnd_site = input site and lnd_part = input op_part"
               lnd_line "input prline"}
            if recno <> ? then do:
               find ln_mstr no-lock where ln_line = lnd_line
                  and ln_site = lnd_site no-error.
               display lnd_line @ prline.
               if available ln_mstr then display ln_desc.
            end.
         end.
         else do:
            status input stline[3].
            readkey.
            apply lastkey.
         end.
      end.

      find pt_mstr no-lock where pt_part = input op_part no-error.
      if not available pt_mstr then do:
         {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
         undo, retry.
      end.

      assign prline.

      find first ln_mstr no-lock where ln_site = site no-error.
      if available ln_mstr or prline <> "" then do:
         /* VERIFY LINE AND SITE */
         find ln_mstr no-lock where ln_line = prline
            and ln_site = site no-error.
         if not available ln_mstr then do:
            {pxmsg.i &MSGNUM=8526 &ERRORLEVEL=3}
            next-prompt prline.
            display "" @ ln_desc.
            undo,retry.
         end.
         display ln_desc.
      end.
      else display "" @ ln_desc.

      /* ADDED SECTION TO LOCATE PROPER SCHEDULE TO UPDATE */
      part = input op_part.
      op = input op_wo_op.

      {gprun.i ""reoptr1b.p""
         "(site, prline, part, op, last_date,
           output routing, output bom_code, output schedule_id)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if keyfunction(lastkey) = "end-error" then undo, retry.

      if schedule_id = ?
      then do:
         msg-type = 3.
         /* UNEXPLODED SCHEDULE WITH CONSUMPTION PERIOD */
         {pxmsg.i &MSGNUM=325 &ERRORLEVEL=msg-type}
         next-prompt op_part.
         undo, retry.
      end.

      /* LOCATE PROPER ROUTING AND BOM CODE */
      {gprun.i ""reop13a.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


      if keyfunction(lastkey) = "end-error" then undo, retry.
      if undo-all then undo, retry.

      find wo_mstr no-lock where recid(wo_mstr) = wo_recno.
      find wr_route no-lock where recid(wr_route) = wr_recno.

      if not wr_milestone
      then do:
         {pxmsg.i &MSGNUM=560 &ERRORLEVEL=3}
         /* OPERATION NOT A MILESTONE */
         undo, retry.
      end.

      if available ro_det then display ro_desc.
      else display wr_desc @ ro_desc.
      find pt_mstr where pt_part = wr_part no-lock no-error.
      if available pt_mstr then display pt_desc1.
      else display " " @ pt_desc1.

      status input.

      do transaction
      with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.


         create op_hist.

         {mfnoptr.i}

         assign
            op_wo_nbr = wr_nbr
            op_emp
            op_wo_op
            op_part
            op_shift = shift
            op_wo_lot = wr_lot
            op_type = "LABOR"
            op_tran_date = today
            op_wkctr = wr_wkctr
            op_mch = wr_mch
            op_date = last_date
            op_site = site
            op_line = prline
            op_earn = earn.

         ophist_recid = recid(op_hist).

         assign
            start_run = "000000"
            stop_run = "000000"
            downtime = 0
            down_rsn = ""
            down_desc = ""
            um = pt_um
            conv = 1.

         display
            op_wkctr
            op_mch
            op_qty_rwrk
            um conv
            " " @ disp_units
            op_act_run
            op_earn
            start_run
            stop_run
            op_trnbr format ">>>>>>>9".

         if is_wiplottrace_enabled() then
            run init_labor_vars in h_wiplottrace_procs.

         find wc_mstr where wc_wkctr = op_wkctr
            and wc_mch = op_mch no-lock no-error.
         if available wc_mstr then do:
            display wc_desc.
            find dpt_mstr no-lock where dpt_dept = wc_dept
               no-error.
            if available dpt_mstr then do:
               op_dept = wc_dept.
               display op_dept dpt_desc.
            end.
            else display " " @ dpt_desc.
         end.
         else display " " @ wc_desc " " @ op_dept " " @ dpt_desc.

         global_rsntyp = "rework".

         set_ophist:
         do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


            run go-set-ophist.
            if keyfunction(lastkey) = "end-error" then undo, leave.

            /* CHECK FOR MASTER SPECIFICATION */
            wr_recno = recid(wr_route).

            /* ADDED FOURTH PARAMETER last_date IN CALL TO mpwindow.i */

            {mpwindow.i wr_part wr_op
               "if wo_routing = """" then wr_part else wo_routing"
               last_date
               }

            if is_wiplottrace_enabled()
               and is_operation_queue_lot_controlled
               (wr_lot, wr_op, OUTPUT_QUEUE)
            then do:
               if next_milestone_operation(wr_lot, wr_op) <> ? then do:
                  run get_destination_wkctr_mch_from_user
                     in h_wiplottrace_procs
                     (input wr_lot,
                     input next_milestone_operation(wr_lot, wr_op),
                     output move_to_wkctr,
                     output move_to_mch,
                     output undo_stat).

                  if undo_stat then undo, retry.
               end.

               run get_std_rework_input_wip_lot_from_user
                  (input wr_lot,
                  input wr_op,
                  input op_qty_rwrk,
                  input conv,
                  input um,
                  input op_site, input op_wkctr, input op_mch,
                  output undo_stat).

               if undo_stat then undo, retry.

               if next_milestone_operation(wr_lot, wr_op) = ?
               then do:
                  lotserial = ''.
                  run std_rework_create_receive_sr_wkfl
                     (wo_lot, op_qty_rwrk / conv, conv, um).

                  wo_recid = wo_recno.
                  {gprun.i ""reisrc02.p""
                     "(output trans-ok, output undo-input)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if not trans-ok or undo-input then undo, retry.

                  run std_rework_check_lots
                     (input op_qty_rwrk * conv, output undo_stat).

                  if undo_stat then undo, retry.
               end.
            end.

            yn = yes.
            {pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=yn
                     &CONFIRM-TYPE='LOGICAL'}
            if yn = no then undo, retry.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         op_qty_rwrk = op_qty_rwrk * conv.

         if is_wiplottrace_enabled()
            and is_operation_queue_lot_controlled
            (wr_lot, wr_op, OUTPUT_QUEUE)
         then do:
            run std_rework_wip_lots
               (input ophist_recid, input move_to_wkctr,
               input move_to_mch).

            for first op_hist where recid(op_hist) = ophist_recid
                  no-lock:
            end.

            if next_milestone_operation(wr_lot, wr_op) = ?
            then do:
               wo_recid = wo_recno.
               {gprun.i ""reisrc04.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

            end.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         msg-counter = 0.
         repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

            release wo_mstr.
            release wr_route.
            find wo_mstr exclusive-lock where recid(wo_mstr) = wo_recno
               no-wait no-error.
            if available wo_mstr then
               find wr_route exclusive-lock
                  where recid(wr_route) = wr_recno no-wait no-error.
            if locked wo_mstr
               or locked wr_route
            then do:
               if locked wo_mstr then locked-file = "wo_mstr".
               else
               if locked wr_route then locked-file = "wr_route".
               if msg-counter modulo 100 = 0 then do:

                  {mfmsg03.i 1400 1 locked-file
                     kblabel(""end-error"") """"
                     "fill(""."",(msg-counter / 100) mod 20)" }
                  readkey pause 1.
                  if keyfunction(lastkey) = "end-error" then leave.
                  apply lastkey.
               end.
               msg-counter = msg-counter + 1.
               next.
            end.
            if available wo_mstr and available wr_route then leave.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.

         hide message.

         if keyfunction(lastkey) = "end-error" then undo, leave.

         pay_rate = wc_lbr_rate.
         if emp_pay_type = "HR" and emp_pay_rate <> 0 then do:
            pay_rate = emp_pay_rate.
            if op_earn > "" and available ea_mstr
               then pay_rate = pay_rate * ea_rate.
         end.

         assign
            wr_act_setup = wr_act_setup + op_act_setup
            wr_act_run = wr_act_run + op_act_run

            wr_recno = recid(wr_route)
            wc_recno = recid(wc_mstr)
            op_recno = recid(op_hist).

         {gprun.i ""reoptrc.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         wr_qty_rwrk = wr_qty_rwrk + op_qty_rwrk.

         if (index("QHS",wr_status) > 0 or wr_status = "" )
            and op_act_run > 0 then wr_status = "R".
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if control_total <> input_total then do:
      {pxmsg.i &MSGNUM=1151 &ERRORLEVEL=2}
   end.
end.
status input.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.
/* * * * * * * INTERNAL PROCEDURES * * * * * * * * * * */

PROCEDURE go-set-ophist:
   do with frame b:
      display input_total with frame a.

      set op_hist.op_wkctr op_mch
      editing:
         {mfnp.i wc_mstr op_wkctr wc_wkctr op_wkctr
            wc_wkctr wc_wkctr}

         if recno <> ? then
            display
               wc_wkctr @ op_wkctr
               wc_mch @ op_mch
               wc_desc.
         find dpt_mstr no-lock where dpt_dept = wc_dept
            no-error.
         if available dpt_mstr then do:
            op_dept = dpt_dept.
            display op_dept dpt_desc.
         end.
         else display " " @ dpt_desc.
      end.

      find wc_mstr where wc_wkctr = op_wkctr
         and wc_mch = op_mch no-lock no-error.
      if not available wc_mstr then do:
         {pxmsg.i &MSGNUM=519 &ERRORLEVEL=3}
         /* WORK CENTER DOES NOT EXIST */
         undo, retry.
      end.
      display wc_desc.

      find dpt_mstr no-lock where dpt_dept = wc_dept no-error.
      if available dpt_mstr then do:
         op_dept = dpt_dept.
         display op_dept dpt_desc.
      end.
      else display " " @ dpt_desc.

      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         set
            op_dept
            op_qty_rwrk
            um conv
            op_act_run
            op_rsn_rwrk op_earn
         editing:
            if frame-field = "op_dept" then do:
               {mfnp.i dpt_mstr op_dept dpt_dept op_dept
                  op_dept dpt_dept}
               if recno <> ? then
                  display dpt_dept @ op_dept dpt_desc.
            end.
            else if frame-field = "op_earn" then do:
               {mfnp.i ea_mstr op_earn ea_earn op_earn
                  ea_earn ea_earn}
               if recno <> ? then
                  display ea_earn @ op_earn ea_desc.
            end.
            else if frame-field = "op_rsn_rwrk" then do:
               {mfnp01.i rsn_ref op_rsn_rwrk rsn_code
                  ""rework"" rsn_type rsn_type}
               if recno <> ? then
                  display
                     rsn_code @ op_rsn_rwrk
                     rsn_desc @ rsn_desc1.
            end.
            else do:
               status input stline[3].
               readkey.
               apply lastkey.
            end.
         end.

         find dpt_mstr where dpt_dept = op_dept
            no-lock no-error.
         if not available dpt_mstr then do:
            next-prompt op_dept.
            {pxmsg.i &MSGNUM=532 &ERRORLEVEL=3}
            /* DEPARTMENT DOES NOT EXIST */
            undo, retry.
         end.
         display dpt_desc.

         if um <> pt_mstr.pt_um or conv <> 1 then do:
            if not conv entered then do:
               {gprun.i ""gpumcnv.p""
                  "(um, pt_um, op_part, output conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               if conv = ? then do:
                  {pxmsg.i &MSGNUM=33 &ERRORLEVEL=2}
                  conv = 1.
               end.
               display conv with frame b.
            end.
            assign
               tot_units = op_qty_rwrk * conv
               disp_units = string(tot_units,"->,>>>,>>9.9<<<<<<<<")
                          + " " + pt_um
               disp_units = fill(" ",max(15 - length(disp_units),0))
                          + disp_units.
            display disp_units with frame b.
         end.
         else display conv " " @ disp_units with frame b.

         find rsn_ref where rsn_code = op_rsn_rwrk
            and rsn_type = "rework" no-lock no-error.
         if available rsn_ref then
            display rsn_desc @ rsn_desc1.
         else do:
            display " " @ rsn_desc1.
            if op_rsn_rwrk > "" then do:
               {pxmsg.i &MSGNUM=534 &ERRORLEVEL=2}
            end.
         end.

         if op_earn > "" then do:
            find ea_mstr where ea_earn = op_earn
               no-lock no-error.
            if not available ea_mstr then do:
               {pxmsg.i &MSGNUM=4025 &ERRORLEVEL=3}
               /* INVALID EARNINGS CODE */
               next-prompt op_earn.
               undo, retry.
            end.
            display ea_desc.
         end.
         else display " " @ ea_desc.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if op_act_run = 0 then
      do on error undo, retry with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

         set start_run stop_run.
         {mfctime.i start_run stop_run}
         op_act_run = elapse.
         display op_act_run.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

      elapse = op_act_run.
      input_total = input_total + op_act_run.

      display input_total with frame a.
   end. /* do with frame b */
end. /* go-set-ophist */

PROCEDURE std_rework_check_lots:
   define input parameter ip_qty_rwrk like op_qty_rwrk no-undo.
   define output parameter op_undo_all like mfc_logical no-undo.

   define variable total_qty as decimal no-undo.

   for each sr_wkfl no-lock
         where sr_userid = mfguser
         and sr_lineid begins '+':
/*GUI*/ if global-beam-me-up then undo, leave.

      if sr_lotser <> rework_to_lotser then do:
         {pxmsg.i &MSGNUM=8466 &ERRORLEVEL=3 &MSGARG1=sr_lotser}
         /* RECEIPT DATA INPUT LOT/SERIAL DOES NOT MATCH  REWORKED LOT/SERIAL */

         op_undo_all = true.
      end.

      total_qty = total_qty + sr_qty.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if total_qty <> ip_qty_rwrk then do:
      {pxmsg.i &MSGNUM=8467 &ERRORLEVEL=3}
      /* RECEIPT DATA INPUT QUANTITY DOES NOT MATCH REWORKED QUANTITY */

      op_undo_all = true.
   end.
END PROCEDURE.

PROCEDURE std_rework_create_receive_sr_wkfl:
   define input parameter ip_wo_id like wo_lot no-undo.
   define input parameter ip_qty as decimal no-undo.
   define input parameter ip_conv as decimal no-undo.
   define input parameter ip_um as character no-undo.

   define variable i as integer no-undo.

   for first wo_mstr where wo_lot = ip_wo_id no-lock:
   end.
   for first pt_mstr where pt_part = wo_part no-lock:
   end.

   for each sr_wkfl exclusive-lock where sr_userid = mfguser:
      delete sr_wkfl.
   end.

   create sr_wkfl.

   assign
      sr_userid = mfguser
      sr_lineid = "+" + wo_part
      sr_site = wo_site
      sr_loc = wo_loc
      sr_lotser = rework_to_lotser
      sr_ref = rework_to_lotser_ref
      sr_qty = ip_qty * ip_conv
      sr_vend_lot = string(ip_conv)
      sr_to_loc = 'wltstrwk'
      sr_rev = ip_um
      .

   if sr_loc = "" then sr_loc = pt_loc.
   if recid(sr_wkfl) = -1 then.
END PROCEDURE.

PROCEDURE std_rework_wip_lots:
   define input parameter ip_ophist_recid as recid no-undo.
   define input parameter ip_move_to_wkctr like wc_wkctr no-undo.
   define input parameter ip_move_to_mch like wc_mch no-undo.

   define variable lot_number_changed like mfc_logical no-undo.
   define variable wl_ophist_recid as recid no-undo.
   define variable qty_rework as decimal no-undo.

   for first op_hist
         where recid(op_hist) = ip_ophist_recid
         exclusive-lock:
   end.

   for first wo_mstr where wo_lot = op_wo_lot no-lock:
   end.

   assign
      lot_number_changed = rework_to_lotser <> rework_lotser
      op_wip_lotser = rework_lotser
      op_wip_ref = rework_lotser_ref
      qty_rework = op_qty_rwrk.

   /* REDUCE THE REJECT QUEUE WIP QOH AT THIS OPERATION FOR THE "FROM" LOT */

   run change_wip_qty_alloc_qoh in h_wiplottrace_procs
      (input op_wo_lot,
      input op_wo_op,
      input rework_lotser,
      input rework_lotser_ref,
      input op_site,
      input op_wkctr,
      input op_mch,
      input REJECT_QUEUE,
      input op_wo_lot,
      input op_wo_op,
      input - op_qty_rwrk).

   if next_milestone_operation(op_wo_lot, op_wo_op) <> ?
   then do:
      /* INCREASE THE INPUT QUEUE WIP QOH AT THE NEXT MILESTONE OPERATION */
      /* FOR THE "TO" LOT*/

      run change_wip_qty_alloc_qoh in h_wiplottrace_procs
         (input op_wo_lot,
         input op_wo_op,
         input rework_to_lotser,
         input rework_to_lotser_ref,
         input op_site,
         input ip_move_to_wkctr,
         input ip_move_to_mch,
         input INPUT_QUEUE,
         input op_wo_lot,
         input next_milestone_operation(op_wo_lot, op_wo_op),
         input op_qty_rwrk).
   end.

   /*UPDATE THE WIP LOT MASTER - QTY REWORKED*/

   run update_wip_lot_master_record in h_wiplottrace_procs
      (input op_wo_lot,
      input rework_prodby_op,
      input rework_lotser,
      input CUM_REWORKED,
      input op_qty_rwrk).

   if lot_number_changed then do:
      /* REGISTER THE OLD LOT AS CONSUMED IN THE TRACING JOURNAL. */
      /* NOTE THAT WE SAY IT'S PRODUCED BY THE PRIOR OPERATION    */
      /* UNLESS WE'RE AT THE FIRST OPERATION.                     */

      run add_trace_record in h_wiplottrace_procs
         (input OPERATION_HISTORY,
         input op_trnbr,
         input CONSUMED_MTL,
         input WIP_MTL,
         input op_wo_lot,
         input op_wo_op,
         input op_part,
         input rework_lotser,
         input '',
         input op_qty_rwrk).

      /*UPDATE THE WIP LOT MASTER - QTY CONSUMED*/

      run update_wip_lot_master_record in h_wiplottrace_procs
         (input op_wo_lot,
         input op_wo_op,
         input rework_lotser,
         input CUM_CONSUMED,
         input op_qty_rwrk).

      /*REGISTER THE NEW LOT AS PRODUCED IN THE TRACING JOURNAL*/

      run add_trace_record in h_wiplottrace_procs
         (input OPERATION_HISTORY,
         input op_trnbr,
         input PRODUCED_MTL,
         input WIP_MTL,
         input op_wo_lot,
         input op_wo_op,
         input op_part,
         input rework_to_lotser,
         input '',
         input op_qty_rwrk).

      /* UPDATE THE WIP LOT MASTER - QTY PRODUCED */

      run update_wip_lot_master_record in h_wiplottrace_procs
         (input op_wo_lot,
         input op_wo_op,
         input rework_to_lotser,
         input CUM_PRODUCED,
         input op_qty_rwrk).
   end. /*if lot_number_changes*/

   if next_milestone_operation(op_wo_lot, op_wo_op) = ?
   then do:
      /* WE ARE AT THE LAST OPERATION SO WE GENERATE          */
      /* TRACING RECORDS TO SHOW THAT THE REWORK-TO LOTSERIAL */
      /* IS CONSUMED AND THE FINISHED MATERIAL LOTSERIALS     */
      /* ARE PRODUCED                                         */

      {gprun.i ""reophist.p""
         "(input op_type,
           input op_wo_lot,
           input op_wo_op,
           input op_emp,
           input op_wkctr,
           input op_mch,
           input op_dept,
           input op_shift,
           input op_date,
           output wl_ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      for first op_hist
            where recid(op_hist) = wl_ophist_recid
            exclusive-lock:
      end.

      /* REGISTER THE NEW LOT AS CONSUMED IN THE TRACING JOURNAL */

      run add_trace_record in h_wiplottrace_procs
         (input OPERATION_HISTORY,
         input op_trnbr,
         input CONSUMED_MTL,
         input WIP_MTL,
         input op_wo_lot,
         input op_wo_op,
         input op_part,
         input rework_to_lotser,
         input '',
         input qty_rework).

      /* UPDATE THE WIP LOT MASTER - QTY CONSUMED */

      run update_wip_lot_master_record in h_wiplottrace_procs
         (input op_wo_lot,
         input op_wo_op,
         input rework_to_lotser,
         input CUM_CONSUMED,
         input qty_rework).

      /* REGISTER THE FINISHED MATERIAL LOTS AS PRODUCED */
      /* IN THE TRACING JOURNAL                          */

      for each sr_wkfl no-lock where sr_userid = mfguser
            and sr_lineid = "+" + op_part:
         /* REGISTER THE FG LOT AS PRODUCED IN THE TRACING JOURNAL */

         run add_trace_record in h_wiplottrace_procs
            (input OPERATION_HISTORY,
            input op_trnbr,
            input PRODUCED_MTL,
            input ITEM_MTL,
            input '',
            input 0,
            input op_part,
            input sr_lotser,
            input '',
            input sr_qty).
      end.
   end.
END PROCEDURE.

PROCEDURE get_std_rework_input_wip_lot_from_user:
   define input parameter ip_wo_id like wl_prodby_id no-undo.
   define input parameter ip_wo_op like wl_prodby_op  no-undo.
   define input parameter ip_qty like wlt_qty no-undo.
   define input parameter ip_umconv_factor as decimal no-undo.
   define input parameter ip_um as character no-undo.
   define input parameter ip_site like si_site no-undo.
   define input parameter ip_wkctr like wc_wkctr no-undo.
   define input parameter ip_mch like wc_mch no-undo.
   define output parameter op_undo_all like mfc_logical no-undo.

   {gprunmo.i
      &program = ""wluisrwi.p""
      &module = "AWT"
      &param = """(input ip_wo_id,
                   input ip_wo_op,
                   input ip_qty,
                   input ip_umconv_factor,
                   input ip_um,
                   input ip_site,
                   input ip_wkctr,
                   input ip_mch,
                   output op_undo_all)"""}

END PROCEDURE.
